<?php
/**
 * 
 * @author Paolo Bertuzzo
 *
 */
namespace User\Helper;

use Zend\View\Helper\HelperInterface;
use Zend\View\Helper\AbstractHelper;
use Zend\View\Model\ViewModel;
use Zend\View\Helper\Partial;
use Utilities\Session\SessionFacade;
use Utilities\Server\Url;
use User\Helper\Model\Country;
use User\Helper\Model\State;

class AddressFormHelper extends Partial
{
    
    /**
     * (non-PHPdoc)
     * @see \Zend\View\Helper\Partial::__invoke()
     */
    public function __invoke($name = NULL, $values = NULL)
    {
        $sessionFacade = new SessionFacade();
        
        // Build up countries array
        $countries = array();
        
        foreach ($values['countries'] as $country)
            array_push($countries, new Country($country->getId(), $country->getName()));

        // Build up states array
        $states = array();
        
        foreach ($values['states'] as $state)
        	array_push($states, new State($state->getId(), $state->getCountryId() , $state->getName()));
        
        return parent::__invoke('helper/address_form', array(
            'type' => $values['type'],
        	'address' => $values['address'],
            'locale' => $sessionFacade->getLocale(),
            'countries' => $countries,
            'states' => $states
        ));
    }
   
}

?>